-- Filename：	GetActivityInfo.lua
-- Author：		2100
-- Date：		2024-10-3
-- Purpose：    查看活动数据
module("GetActivityInfo" , package.seeall)

require "script/model/utils/ActivityConfigUtil"
require "script/model/utils/ActivityConfig"
require "script/network/Network"
require "script/utils/TimeUtil"
require "script/ui/item/ItemUtil"
require "script/ui/tip/AnimationTip"
require "script/utils/LuaUtil"
--活动中英文对照表,表里面没有的默认显示英文名字
local activity_name = {
    ["travelShop"]="云游商人",
    ["version"]="版本",
    ["annivTenthTask"]="周年蛋糕任务表",
    ["supply"]="吃烧鸡送金币",
    ["stepCounter"]="计步活动",
    ["doubleCharge"]="双重好礼",
    ["cardgift"]="超级基金",
    ["doubleChargeScore"]="双重好礼积分条件",--双重好礼积分获取条件
    ["desact"]="新类型福利活动",
    ["lordwar"]="群雄争霸赛",
    ["topupReward"]="充值放送",
    ["groupon"]="跨服团购？",--貌似是以前的活动，现在好像没有了
    ["topupFund"]="充值回馈",
    ["worldcarnival"]="嘉年华比赛",
    ["logindraw"]="周年抽奖",
    ["luxuryRecharge"]="累充精选豪礼",
    ["annivFifth"]="周年纪念册",
    ["worldgroupon"]="跨服团购",
    ["annivTenthExchange"]="周年蛋糕兑换表",
    ["blackshop"]="黑市",
    ["annivSixthTask"]="贮金任务",
    ["mineralelves"]="资源矿宝藏",
    ["festival"]="节日活动",
    ["timelimitsign"]="吃蛋糕",
    ["annivTask"]="周年任务",
    ["chargeRaffle"]="幸运转盘",
    ["worldarena"]="巅峰对决",
    ["frontShow"]="主界面",--主界面背景、特效、背景音乐
    ["luckyDoi"]="幸运锦鲤",
    ["annivSeven"]="节日盛典",
    ["festivalActReward"]="节日狂欢",
    ["actpayback"]="补偿活动",
    ["rebate"]="豪礼放送",
    ["privateOrderScore"]="私人定制分数",
    ["limitFund"]="限时基金活动",
    ["rechargeGift"]="缤纷回馈",
    ["fsReborn"]="战魂重生活动",
    ["anniv"]="庆典",
    ["validity"]="活动屏蔽配置",
    ["heroShopReward"]="活动卡包奖励",
    ["annivTenthCake"]="周年蛋糕",
    ["monthlyCardGift"]="月卡",
    ["envelope"]="红包",
    ["worldteam"]="三国激斗",
    ["warOrder"]="放三令牌",
    ["robTomb"]="皇陵寻宝",
    ["treasureBowl"]="聚宝盆",
    ["guildwar"]="军团争霸赛",
    ["rescoreshop"]="充值积分活动",
    ["getrich"]="迎财神",
    ["mysteryFair"]="神秘集市",
    ["oneRecharge"]="单充回馈",
    ["annivEighth"]="周年贺彩（敲鼓）",
    ["arenaDoubleReward"]="竞技场双倍奖励",
    ["annivSixth"]="贮金",
    ["spend"]="消费累积",
    ["regress"]="回归有礼",
    ["worldcup"]="世界杯",
    ["roulette"]="积分轮盘",
    ["annivTenthRecharge"]="周年蛋糕充值表",
    ["annivTenthPuzzle"]="周年蛋糕拼图表",
    ["discount"]="精品折扣",
    ["actExchange"]="神将道具限时兑换",
    ["annivNinth"]="周年筑梦（匹配）",
    ["privateOrder"]="私人订制",
    ["heroShop"]="限时神将",
    ["scoreShop"]="积分商店",
    ["madcharge"]="连充好礼",
    ["weekfoundation"]="周基金",
    ["mission"]="悬赏榜",
    ["festivalAct"]="节日狂欢活动",
    ["happySign"]="欢乐签到",
    ["limitShop"]="限时商店",
    ["annivSevenTask"]="节日盛典任务",
    ["guildpoint"]="争霸天下",
    ["signActivity"]="累计登录",
    ["weal"]="福利活动（积分翻卡）",
    ["copyFund"]= "副本基金",
    ["annivElevenSign"]="周年签到（气球）",
    ["annivElevenCopyFund"]="周年活动基金",
    ["annivElevenLucky"]="周年夺宝（气球）",
    ["annivElevenCarnival"]="周年任务（气球）",
    ["directWarOrder"]="直购战令",
    ["directSubsidyCard"]="补给卡",
    ["directAssitCard"]="助力卡"

}
--屏蔽的活动配置，主要是一些任务信息
local shield_activity={"doubleChargeScore","festivalAct","annivSevenTask","annivTask","annivSixthTask","privateOrderScore"}
local serverVersion = nil --活动版本号
local _info = nil -- 保存活动信息，目前没用用到
local next_open_activity = {} -- 即将开启的活动列表
local min_activity_time = 0
local activity_time_count = {}
local file_time = nil
--local persistentFile = CCFileUtils:sharedFileUtils():getWritablePath() -- /data/data/com.sincetimes.fknsg/files/

function setActivityInfo(info)
    _info = info
end

function getActivityInfo()
    return _info
end

function getActivityInfoByKey(k)
    return _info.arrData[k]
end
-- para：时间戳  return：时间格式：2014年06月01日 add by licong
-- TimeUtil.getTimeForDayTwo( m_time )
-- para：时间戳  return：时间格式：2014-06-01 01:01:01  add by chengliang
-- TimeUtil.getTimeFormatYMDHMS( m_time )

--↓↓↓↓↓↓↓↓↓↓↓↓↓↓活动请求及数据处理↓↓↓↓↓↓↓↓↓↓↓↓↓↓
function init()
    _info=nil
    serverVersion = nil
    next_open_activity = {}
    min_activity_time = 0
    activity_time_count = {}
    file_time = nil
end

function preGetActivityInfo()
    init()
    local isPushMsg = true
	function preGetActivityInfoCallBack( cbFlag, dictData, bRet )
		if(dictData.err== "ok") then
			--printTable("new getActivityConf", dictData)
			setActivityInfo(dictData.ret)
			process(dictData.ret, isPushMsg)
        end
    end
    --ActivityConfigUtil.loadPersitentActivityConfig()
    --得到配置版本号
    local version = 0--tonumber(ActivityConfig.ConfigCache.version)-1
	local args= CCArray:create()
	args:addObject(CCInteger:create(version))
	Network.no_loading_rpc(preGetActivityInfoCallBack, "activity.getActivityConf", "activity.getActivityConf", args, true)
end

function process( activity_data, isPushMsg)
	--版本对比
    -- printTable1(activity_data)
    local oldVersion = loadFileVersion() or 0
	serverVersion = tonumber(activity_data.version) or 0
    -- prints(serverVersion)
    -- prints("ceshi")
    local activityBuffer = "作者：胡奕桥\n活动文件更新日期："..TimeUtil.getTimeFormatYMDHMS(serverVersion).."\n获取最新活动信息请加诸天群：694526134\n"	--新活动
    local shield=false
    --按活动开始时间排序
    local data = {}
    local data_key_table={}
    local data_table_len  = 0
    for k,v in pairs(activity_data.arrData) do
        if(data_table_len==0)then
            table.insert(data_key_table,k)
            data_table_len = data_table_len + 1
        else
            for i=1,data_table_len do
                if(tonumber(v.start_time)<tonumber(activity_data.arrData[data_key_table[i]].start_time))then
                    table.insert(data_key_table,i,k)
                    data_table_len = data_table_len+1
                    break
                elseif(i==data_table_len)then
                    table.insert(data_key_table,k)
                    data_table_len = data_table_len+1
                    break
                end
            end
        end
    end
    --prints(table.concat(data_key_table,","))
    --printTable1(data)
	--添加缓存数据
    local curTime = TimeUtil.getSvrTimeByOffset(0)
    local timeModify = 0
    if(serverVersion<TimeUtil.getCurDayZeroTime(curTime))then
        timeModify = 86400*3
    end
    for i=1,data_table_len do
        local k=data_key_table[i]
        local v=activity_data.arrData[data_key_table[i]]
        --prints("data "..k.." "..v.start_time.." "..serverVersion)
        if(tonumber(v.start_time)>=TimeUtil.getCurDayZeroTime(serverVersion)-timeModify)then
            shield=false
            for i=1,#shield_activity do
                if (shield_activity[i]==tostring(k))then
                    shield=true
                    break
                end
            end

            --处理新活动通知
            if(isPushMsg == true and shield == false) then
                table.insert(next_open_activity,tostring(k))
                if(activity_time_count[v.start_time]==nil)then
                    activity_time_count[v.start_time]=1
                elseif(activity_time_count[v.start_time]>=0)then
                    activity_time_count[v.start_time] = activity_time_count[v.start_time]+1
                else
                    -- prints("activity_time_count[v.start_time] "..v.start_time)
                end
                -- printTable1(activity_time_count)
                for k,v in pairs(activity_time_count)do
                    min_activity_time = tonumber(k)
                    if(v>=3)then
                        if(min_activity_time==0)then
                            min_activity_time = tonumber(k)
                            break
                        else
                            if(min_activity_time>tonumber(k))then
                                min_activity_time = tonumber(k)
                                break
                            end
                        end
                    end
                end
            end 
        end
	end
    if(oldVersion >= serverVersion)then
        AnimationTip.showTip("当前活动日期："..TimeUtil.getTimeForDayTwo(min_activity_time).."，暂未更新，请耐心等待！")
        return
    end
    AnimationTip.showTip("当前活动日期："..TimeUtil.getTimeForDayTwo(min_activity_time))
    activityBuffer = activityBuffer..TimeUtil.getTimeForDayTwo(min_activity_time).."活动（截止时间为兑换截止时间，有些活动在前一天结束，最后一天只能兑换）\n"
    --printTable("ActivityConfig.ConfigCache",ActivityConfig.ConfigCache)
	reviceNewActivity(activityBuffer)
end
function loadFileVersion()
    local inputFile = nil
    local versionFile = "/storage/emulated/0/Download/放三活动版本.txt"
	--判断文件是否存在
	if(CCFileUtils:sharedFileUtils():isFileExist(versionFile) == true) then
		inputFile      = versionFile
	else
        return 0
	end
	--读取持久化的活动配置
	io.input(inputFile)
	local activityBuffer = io.read("*all")
	print("loadFileVersion: "..activityBuffer)

	if(activityBuffer == nil or activityBuffer == "") then
		--读取失败
		return 0
	end
    return tonumber(activityBuffer)
end
function reviceNewActivity(activityBuffer)
    for i=1,#next_open_activity do
        local k = next_open_activity[i]
        local v=getActivityInfo().arrData[k]
        if(i>1)then
            if(v.start_time~=getActivityInfoByKey(next_open_activity[i-1]).start_time)then
                activityBuffer = activityBuffer.."\n"
            end
        end
        local name = activity_name[k] or k
        local space_len= 10-string.lenUTF8(name)
        local space_str = ""
        for i=1,space_len do
            space_str = space_str.."—"
        end
        local start_time = TimeUtil.getTimeFormatYMDHMS(tonumber(v.start_time))
        local end_time = TimeUtil.getTimeFormatYMDHMS(tonumber(v.end_time))
        activityBuffer = activityBuffer..name..space_str.."开始时间:"..start_time.."\t".."结束时间:"..end_time.."\n"
    end
    local path = "/storage/emulated/0/Download/放三活动"..TimeUtil.getTimeForDayTwo(min_activity_time)..".txt"
    local file = io.open(path,"w")
	file:write(activityBuffer)
	file:close()
    local versionPath = "/storage/emulated/0/Download/放三活动版本.txt"
    local versionfile = io.open(versionPath,"w")
    --io.output(versionfile)
    -- prints(serverVersion)
	versionfile:write(tostring(serverVersion))
	versionfile:close()
    -- prints("生成文件："..path)
    -- prints("Version:"..serverVersion)
    addDetailInfo(path)
end
function addDetailInfo(path)
    local file = io.open(path,"a+")
    --print(#next_open_activity)
    for i=1,#next_open_activity do
        local activity = next_open_activity[i]
        -- 吃蛋糕
        if(activity=="timelimitsign")then
            file:write(timelimitsign(1))
        elseif(activity=="topupFund")then
            file:write(topupFund(1))
        elseif(activity=="rechargeGift")then
            file:write(rechargeGift(1))
        elseif(activity=="luxuryRecharge")then
            file:write(luxuryRecharge(1))
        elseif(activity=="anniv")then
            file:write(anniv(1))
        elseif(activity=="oneRecharge")then
            file:write(oneRecharge(1))
        elseif(activity=="annivSeven")then
            file:write(annivSeven(1))
        elseif(activity=="festivalActReward")then
            file:write(festivalActReward(1))
        elseif(activity=="worldgroupon")then
            file:write(worldgroupon(1))
        elseif(activity=="directWarOrder")then
            file:write(directWarOrder(1))
        end
    end
	file:close()
    --print("添加内容到："..path)
end

--↓↓↓↓↓↓↓↓↓↓↓↓↓↓活动详细信息解析↓↓↓↓↓↓↓↓↓↓↓↓↓↓
function oneRecharge(index)
    print("单充回馈")
    local ret="----------------------------------------------------------------------------\n单充回馈\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.oneRecharge.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        local reward_type = tonumber(v.type)-- 1：领取所有物品 2：选择一个
        local payReward = v.payReward
        local payNum = v.payNum
        ret = ret.."充值"..payNum.."金币  奖励"
        if(reward_type==1)then
            ret=ret.."领取全部："
        elseif(reward_type==2)then
            ret=ret.."任选一个："
        end
        ret = ret..print3TupleNum(string.split(payReward,","),index).."\n"
    end
    return ret
end
function festivalActReward(index)
    --print("节日狂欢")
    local ret="----------------------------------------------------------------------------\n节日狂欢\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.festivalActReward.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        if(tonumber(v.bigtype)==3)then
            local need = string.split(v.need,",")
            local reward = string.split(v.exchange,",")
            local times = v.exchangetime
            ret = ret.."需要物品："..print3TupleNum(need,index).."  兑换次数："..times.."  奖励："..print3TupleNum(reward,index).."\n"
        end
    end
    return ret
end
function worldgroupon(index)
    --print("跨服团购")
    local ret="----------------------------------------------------------------------------\n跨服团购\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.worldgroupon.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        local item = string.split(v.item,",")
        local times = v.type
        local price = v.price
        ret = ret.."物品："..print3TupleNum(item,index).."  购买次数："..times.."  初始价格："..price.."\n"
    end
    return ret
end
function luxuryRecharge(index)
    --print("累充精选豪礼")
    local ret="----------------------------------------------------------------------------\n累充精选豪礼\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.luxuryRecharge.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        ret = ret.."充值"..v.addGold.."金币  奖励"
        local reward_type = v.addGold_select
        if (reward_type=="")then
            ret = ret.."领取全部："
        elseif(reward_type=="1")then
            ret = ret.."任选一个："
        end
        ret = ret..print3TupleNum(string.split(v.reward,","),index).."\n"
        if(v.extra~= "")then
            ret = ret.."    额外奖励:"..print3TupleNum(string.split(v.extra,","),index).."\n\n"
        end
    end
    return ret
end
function rechargeGift(index)
    --print("缤纷回馈")
    local ret="----------------------------------------------------------------------------\n缤纷回馈\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.rechargeGift.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        ret = ret.."充值"..v.expenseGold.."金币  奖励"
        local reward_type = tonumber(v.type)
        if (reward_type==1)then
            ret = ret.."领取全部："
        elseif(reward_type==2)then
            ret = ret.."任选一个："
        end
        ret = ret..print3TupleNum(string.split(v.reward,","),index).."\n"
    end
    return ret
end
function topupFund(index)
    --print("充值回馈")
    local ret="----------------------------------------------------------------------------\n充值回馈\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.topupFund.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        ret = ret.."充值"..v.expenseGold.."金币  奖励："..print3TupleNum(string.split(v.reward,","),index).."\n"
    end
    return ret
end
function annivSeven(index)
    --print("节日盛典")
    local ret="----------------------------------------------------------------------------\n节日盛典\n"
    local print_index = index or 0
    local brand_reward =  string.split(ActivityConfig.ConfigCache.annivSeven.data[1].brand_reward,",")
    local brand_all =  string.split(ActivityConfig.ConfigCache.annivSeven.data[1].brand_all,",")
    local reward_show =  string.split(ActivityConfig.ConfigCache.annivSeven.data[1].reward_show,",")
    local reward_show_dict = {}
    for i=1,#reward_show do 
        local gift_name = reward_show[i]
        local temp = string.split(gift_name,"|")
        local lv = tonumber(temp[1])
        local name = temp[3]
        reward_show_dict["lv"..lv] = name
    end
    for i=1,8 do
        ret = ret..reward_show_dict["lv"..i].."："..print4TupleNum(brand_reward,index,i).."\n"
    end
    ret = ret..reward_show_dict["lv"..9].."："..print3TupleNum(brand_all,index).."\n"
    return ret
end
function anniv(index)
    --print("庆典")
    local ret="----------------------------------------------------------------------------\n庆典\n"
    local print_index = index or 0
    local exchange = ActivityConfig.ConfigCache.anniv.data[1].exchange
    local task_id_list = string.split(exchange,"|")
    for i=1,#task_id_list do
        local task_id = tonumber(task_id_list[i])
        local exchange_cost = string.split(ActivityConfig.ConfigCache.annivTask.data[task_id].exchange_cost,",")
        local exchange_get = string.split(ActivityConfig.ConfigCache.annivTask.data[task_id].exchange_get,",")
        ret = ret.."需要物品："..print3TupleNum(exchange_cost,index).."  奖励："..print3TupleNum(exchange_get,index).."\n"
    end
    return ret
end
function timelimitsign(index)
    --print("吃蛋糕")
    local ret="----------------------------------------------------------------------------\n吃蛋糕\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.timelimitsign.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        local time = string.split(v.reward_times,"|")
        local time_start = tonumber(time[1])
        local time_end = tonumber(time[2])
        ret = ret.."时间："..TimeUtil.getNewTime(time_start).."——"..TimeUtil.getNewTime(time_end).."  奖励："..print3TupleNum(string.split(v.reward,","),print_index).."\n"
    end
    return ret
end

function directWarOrder(index)
    --print("直购战令")
    local ret="----------------------------------------------------------------------------\n直购战令\n"
    local print_index = index or 0
    local data = ActivityConfig.ConfigCache.directWarOrder.data
    local keysArray = {}
    for key, _ in pairs(data) do
        table.insert(keysArray, key)
    end
    table.sort(keysArray)
    for i=1,#keysArray do
        local v = data[keysArray[i]]
        local gold_cost = v.gold_cost
        ret = ret.."消耗"..gold_cost.."金币\n"
        for k=1,3 do
            local reward_free = v["reward_free"..k]
            local reward_pay = v["reward_pay"..k]
            ret = ret.."免费"..k.." "..print3TupleNum(string.split(reward_free,","),print_index).."    付费"..k.." "..print3TupleNum(string.split(reward_pay,","),print_index).."\n"
        end
        ret=ret.."\n"
    end
    return ret
end
--↓↓↓↓↓↓↓↓↓↓↓↓↓↓活动详细信息解析工具函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓

-- 递归生成物品信息字符串，index表示礼包递归层数，-1表示不限制递归层数
function printItem(items,index)
    --print("printItem"..index)
    local ret = ""
    local print_index = index or 0
    if(print_index==0)then
        --print("items_len: " .. #items)
        if(#items>0)then
            --print(items[1].name.."*"..items[1].num)
        end
    end
    if(#items==0)then
        local item = items
        ret = ret..item.name.."*"..item.num
        if(print_index ~= 0)then
            if(item.choose==1)then
                ret = ret.."(获得所有:"
                for j=1,#item.content do
                    local choose = item.content[j]
                    if(choose.choose~=0)then
                        ret=ret..printItem(choose,print_index-1)
                    else
                        ret=ret..choose.name.."*"..choose.num..", "
                    end
                end
                ret = ret..")"
            elseif (item.choose==2)then
                ret = ret.."(任选一个:"
                for j=1,#item.content do
                    local choose = item.content[j]          
                    if(choose.choose~=0)then
                        ret=ret..printItem(choose,print_index-1)
                    else
                        ret=ret..choose.name.."*"..choose.num..", "
                    end
                end
                ret = ret..")"
            end
        end
        ret = ret..", "
        return ret
    end
    for i=1,#items do
        local item = items[i]
        ret = ret..item.name.."*"..item.num
        if(print_index ~= 0)then
            if(item.choose==1)then
                ret = ret.."(获得所有:"
                for j=1,#item.content do
                    local choose = item.content[j]
                    if(choose.choose~=0)then
                        ret=ret..printItem(choose,print_index-1)
                    else
                        ret=ret..choose.name.."*"..choose.num..", "
                    end
                end
                ret = ret..")"
            elseif (item.choose==2)then
                ret = ret.."(任选一个:"
                for j=1,#item.content do
                    local choose = item.content[j]        
                    if(choose.choose~=0)then
                        ret=ret..printItem(choose,print_index-1)
                    else
                        ret=ret..choose.name.."*"..choose.num..", "
                    end
                end
                ret = ret..")"
            end
        end
        ret = ret..", "
    end
    return ret
end
--index表示礼包递归层数，-1表示不限制递归层数
function print3TupleNum(p3TupleStr,index)
    local index = index or 0
    --print("print3TupleNum"..index)
    local items = get3TupleNum(p3TupleStr)
    return printItem(items,index)
end

function getAll3TupleNum(p3TupleStr_list)
    --print("getAll3TupleNum "..type(p3TupleStr_list))
    local ret = {}
    for i=1,#p3TupleStr_list do
        p3TupleStr=p3TupleStr_list[i]
        table.insert(ret,get3TupleNum(p3TupleStr))
    end 
    return ret
end

function get3TupleNum(p3TupleStr)
    --print("get3TupleNum "..type(p3TupleStr))
    if(type(p3TupleStr)=="table")then
        return getAll3TupleNum(p3TupleStr)
    end
    if(type(p3TupleStr)=="string")then
        if(string.find(p3TupleStr,",")~=nil)then
            local p3TupleStr_list = string.split(p3TupleStr,",")
            return getAll3TupleNum(p3TupleStr_list)
        end
    end
    local ret = {["type"]="",["name"]="",["num"]="0",["choose"]=0,["content"]={}}
	local itemInfo = string.split(p3TupleStr, "|")
	local itemType = tonumber(itemInfo[1])
    local itemId  = tonumber(itemInfo[2])
    local itemNum  = tonumber(itemInfo[3])
    ret.num = itemNum
	if itemType == 1 then
        -- 银币
        ret.type = "银币"
        ret.name = "银币"
    elseif itemType == 2  then
        -- 将魂
        ret.type = "将魂"
        ret.name = "将魂"
    elseif itemType == 3  then
        -- 金币
        ret.type = "金币"
        ret.name = "金币"
    elseif itemType == 4 then
        -- 体力(wu)
        ret.type = "体力(wu)"
        ret.name = "体力"
    elseif itemType == 5  then
        -- 耐力(wu)
        ret.type = "耐力(wu)"
        ret.name = "耐力"
    elseif itemType == 6  then
    	--物品
        d = ItemUtil.getItemById(itemId)
		ret.type = "单个物品"
        ret.name = d.name
        if(d.award_item_id~=nil and d.award_item_id~="")then
            ret.choose = 1
            ret.content = get2TupleNum(string.split(d.award_item_id,","))
        elseif(d.choose_items~=nil and d.choose_items~="")then
            ret.choose = 2
            ret.content = get3TupleNum(string.split(d.choose_items,","))
        end
    elseif itemType == 7  then
        --多个物品
        d = ItemUtil.getItemById(itemId)
		ret.type = "多个物品"
        ret.name = d.name
        if(d.award_item_id~=nil and d.award_item_id~="")then
            print("award_item_id"..d.award_item_id)
            ret.choose = 1
            ret.content = get2TupleNum(string.split(d.award_item_id,","))
        elseif(d.choose_items~=nil and d.choose_items~="")then
            print("choose_items"..d.choose_items)
            ret.choose = 2
            ret.content = get3TupleNum(string.split(d.choose_items,","))
        end
    elseif itemType == 8  then
        -- 等级*银币(wu)
        ret.type = "等级*银币(wu)"
        ret.name = "银币"
    elseif itemType == 9  then
        -- 等级*将魂(wu)
        ret.type = "等级*将魂(wu)"
        ret.name = "将魂"
    elseif itemType == 10 then
        -- 单个英雄 类型10 类型id|物品数量默认1|英雄id  以前约定特殊处理(wu)
        ret.type = "单个英雄"
        require "db/DB_Heroes"
        ret.name = DB_Heroes.getDataById(itemId).name
    elseif itemType == 11  then
        -- 魂玉
        ret.type = "魂玉"
        ret.name = "魂玉"
    elseif itemType == 12   then
        -- 声望
        ret.type = "声望"
        ret.name = "声望"
    elseif itemType == 13  then
        -- 多个英雄(wu)
        ret.type = "多个英雄(wu)"
        require "db/DB_Heroes"
        ret.name = DB_Heroes.getDataById(itemId).name
    elseif itemType == 14  then
        -- 宝物碎片
        ret.type = "宝物碎片"
        ret.name = "宝物碎片"
    elseif itemType == 15  then
        -- 军团个人贡献
        ret.type = "军团个人贡献"
        ret.name = "军团个人贡献"
    elseif itemType == 16  then
        -- 军团建设度
        ret.type = "军团建设度"
        ret.name = "军团建设度"
    elseif itemType == 17  then
        -- 比武荣誉
        ret.type = "比武荣誉"
        ret.name = "比武荣誉"
    elseif itemType == 18  then
    	--粮草
        ret.type = "粮草"
        ret.name = "粮草"
    elseif itemType == 19 then
    	-- 神兵令
        ret.type = "神兵令"
        ret.name = "神兵令"
    elseif itemType == 20 then
    	--战功
        ret.type = "将魂"
        ret.name = "将魂"
    elseif itemType == 21  then
    	-- 天工令
        ret.type = "天工令"
        ret.name = "天工令"
    elseif itemType == 22  then
    	--争霸令
        ret.type = "争霸令"
        ret.name = "争霸令"
    elseif itemType == 23 then
    	--炼狱令
        ret.type = "炼狱令"
        ret.name = "炼狱令"
    elseif itemType == 24 then
    	-- 名望
        ret.type = "名望"
        ret.name = "名望"
    elseif itemType == 25  then
    	-- 跨服荣誉
        ret.type = "跨服荣誉"
        ret.name = "跨服荣誉"
	elseif itemType == 26  then
		-- 将星 
        ret.type = "将星"
        ret.name = "将星"
    elseif itemType == 27 then
   		-- 国战积分
        ret.type = "国战积分"
        ret.name = "国战积分"
   	elseif itemType == 28  then
   		-- 兵符积分
        ret.type = "兵符积分"
        ret.name = "兵符积分"
    elseif itemType == 29 then
   		-- 科技图纸
        ret.type = "科技图纸"
        ret.name = "科技图纸"
    elseif itemType == 30 then
   		-- 试炼币
        ret.type = "试炼币"
        ret.name = "试炼币"
    elseif itemType == 31 then
   		-- 星魄
        ret.type = "星魄"
        ret.name = "星魄"
    elseif itemType == 32 then
   		-- 经验
        ret.type = "经验"
        ret.name = "经验"
    elseif itemType == 33 then
   		-- 经验*等级
        ret.type = "经验*等级"
        ret.name = "经验"
    elseif itemType == 34  then
   		-- 悬赏币  
        ret.type = "悬赏币"
        ret.name = "悬赏币"
    elseif itemType == 35  then
   		-- 魔王币  
        ret.type = "魔王币"
        ret.name = "魔王币"
    elseif itemType == 36  then
   		-- 军工
        ret.type = "军功"
        ret.name = "军功"
    elseif itemType == 37  then
   		-- 功绩
        ret.type = "功绩"
        ret.name = "功绩"
    elseif itemType == 38  then
   		--原石数量
        ret.type = "原石数量"
        ret.name = "原石数量"
   	elseif itemType == 39  then
   		--荣耀积分
        ret.type = "荣耀积分"
        ret.name = "荣耀积分"
    elseif itemType == 40  then
        --抽奖券
        ret.type = "抽奖券"
        ret.name = "抽奖券"
   	elseif itemType == 41  then
   		--竹简积分
        ret.type = "竹简积分"
        ret.name = "竹简积分"
   	elseif itemType == 42  then
   		--每日任务积分
        ret.type = "每日任务积分"
        ret.name = "每日任务积分"
   	elseif itemType == 43  then
   		--威名
        ret.type = "威名"
        ret.name = "威名"
   	elseif itemType == 44  then
   		--群雄争霸令
        ret.type = "群雄争霸令"
        ret.name = "群雄争霸令"
   	elseif itemType == 45  then
   		--神器成就点数
        ret.type = "神器成就点数"
        ret.name = "神器成就点数"
   	elseif itemType == 46  then
   		--跨服悬赏币
        ret.type = "跨服悬赏币"
        ret.name = "跨服悬赏币"
   	elseif itemType == 47  then
   		--跨服悬赏积分
        ret.type = "跨服悬赏积分"
        ret.name = "跨服悬赏积分"
   	elseif itemType == 48  then
   		--66币
        ret.type = "66币"
        ret.name = "66币"
   	elseif itemType == 49  then
   		--贮金
        ret.type = "贮金"
        ret.name = "贮金"
   	elseif itemType == 50  then
   		--盛典金币
        ret.type = "盛典金币"
        ret.name = "盛典金币"
   	elseif itemType == 51  then
   		--盛典银币
        ret.type = "盛典银币"
        ret.name = "盛典银币"
   	elseif itemType == 52  then
   		--神兽试炼币
        ret.type = "神兽试炼币"
        ret.name = "神兽试炼币"
    elseif itemType == 53  then
   		--高级悬赏币
        ret.type = "高级悬赏币"
        ret.name = "高级悬赏币"
    elseif itemType == 54  then
   		--幻化修炼币
        ret.type = "幻化修炼币"
        ret.name = "幻化修炼币"
    elseif itemType == 55  then
   		--特惠礼券
        ret.type = "特惠礼券"
        ret.name = "特惠礼券"
    elseif itemType == 56  then
   		--九周年经验
        ret.type = "九周年经验"
        ret.name = "九周年经验"
    elseif itemType == 57  then
   		--红颜精魄
        ret.type = "红颜精魄"
        ret.name = "红颜精魄"
    elseif itemType == 58  then
   		--点券
        ret.type = "点券"
        ret.name = "点券"
    elseif itemType == 59  then
   		--锦鲤号
        ret.type = "锦鲤号"
        ret.name = "锦鲤号"
    elseif itemType == 99  then
   		--逐鹿中原积分
        ret.type = "逐鹿中原积分"
        ret.name = "逐鹿中原积分"
   	else
    end
    return ret
end


function getAll2TupleNum(p2TupleStr_list)
    local ret = {}
    for i=1,#p2TupleStr_list do
        p2TupleStr=p2TupleStr_list[i]
        table.insert(ret,get3TupleNum("7|"..p2TupleStr))
    end 
    return ret
end

function get2TupleNum(p2TupleStr)
    if(type(p2TupleStr)=="table")then
        return getAll2TupleNum(p2TupleStr)
    end
    if(type(p2TupleStr)=="string")then
        if(string.find(p2TupleStr,",")~=nil)then
            local p2TupleStr_list = string.split(p2TupleStr,",")
            return getAll2TupleNum(p2TupleStr_list)
        end
    end
    return get3TupleNum("7|"..p2TupleStr)
end

function getAll4TupleNum(p4TupleStr_list)
    local ret = {}
    for i=1,#p4TupleStr_list do
        p4TupleStr=p4TupleStr_list[i]
        local itemInfo = string.split(p4TupleStr,"|")
        if(ret[tonumber(itemInfo[1])]==nil)then
            ret[tonumber(itemInfo[1])]={}
        end
        table.insert(ret[tonumber(itemInfo[1])],get3TupleNum(itemInfo[2].."|"..itemInfo[3].."|"..itemInfo[4]))
    end 
    return ret
end

function get4TupleNum(p4TupleStr)
    if(type(p4TupleStr)=="table")then
        return getAll4TupleNum(p4TupleStr)
    end
    if(type(p4TupleStr)=="string")then
        if(string.find(p4TupleStr,",")~=nil)then
            local p4TupleStr_list = string.split(p4TupleStr,",")
            return getAll4TupleNum(p4TupleStr_list)
        end
    end
    local ret={}
    local itemInfo=string.split(p4TupleStr,"|")
    if(ret[tonumber(itemInfo[1])]==nil)then
        ret[tonumber(itemInfo[1])]={}
    end
    table.insert(ret[tonumber(itemInfo[1])],get3TupleNum(itemInfo[2].."|"..itemInfo[3].."|"..itemInfo[4]))
    return ret
end

function print4TupleNum(p4TupleStr,index,key)
    local ret=""
    local items = get4TupleNum(p4TupleStr)
    local find_key = nil
    if(key~=nil)then
        find_key = key
    end
    for k,v in pairs(items) do
        if(find_key)then
            if(k==find_key)then
                ret = ret..k..":"..printItem(v,index)
                break
            end
        else
            ret = ret..k..":"..printItem(v,index).."\n"
        end
    end
    return ret
end
--↓↓↓↓↓↓↓↓↓↓↓↓↓↓表格打印函数，结果会输出到文件↓↓↓↓↓↓↓↓↓↓↓↓↓↓
function GetTalbleMapLen(tab)
    local len = 0
    for _, v in pairs(tab) do        
        if v then len = len+1 end        
    end
    return len
end
-- log输出格式化
local function logPrint(str)
    str = "Log output date: "..  TimeUtil.getTimeFormatYMDHMS(TimeUtil.getSvrTimeByOffset()).."\n".. str
    local path = "/storage/emulated/0/Download/"..TimeUtil.getTimeFormatYMDHMS(TimeUtil.getSvrTimeByOffset()).."fknsg.log"
    local file = io.open(path,"w")
	file:write(str)
	file:close()
end
 
-- key值格式化
local function formatKey(key)
    local t = type(key)
    if t == "number" then
        return "["..key.."]"
    elseif t == "string" then
        local n = tonumber(key)
        if n then
            return "["..key.."]"
        end
    end
    return key
end
 
-- 栈
local function newStack()
    local stack = {
        tableList = {}
    }
    function stack:push(t)
        table.insert(self.tableList, t)
    end
    function stack:pop()
        return table.remove(self.tableList)
    end
    function stack:contains(t)
        for _, v in ipairs(self.tableList) do
            if v == t then
                return true
            end
        end
        return false
    end
    return stack
end
 
-- 输出打印table表 函数
function printTable1(...)
    local args = {...}
    for k, v in pairs(args) do
        local root = v
        if type(root) == "table" then
            local temp = {
                "------------------------ printTable start ------------------------\n",
                "local tableValue".." = {\n",
            }
            local stack = newStack()
            local function table2String(t, depth)
                stack:push(t)
                if type(depth) == "number" then
                    depth = depth + 1
                else
                    depth = 1
                end
                local indent = ""
                for i=1, depth do
                    indent = indent .. "    "
                end
                for k, v in pairs(t) do
                    local key = tostring(k)
                    local typeV = type(v)
                    if typeV == "table" then
                        if key ~= "__valuePrototype" then
                            if stack:contains(v) then
                                table.insert(temp, indent..formatKey(key).." = {检测到循环引用!},\n")
                            else
                                table.insert(temp, indent..formatKey(key).." = {\n")
                                table2String(v, depth)
                                table.insert(temp, indent.."},\n")
                            end
                        end
                    elseif typeV == "string" then
                        table.insert(temp, string.format("%s%s = \"%s\",\n", indent, formatKey(key), tostring(v)))
                    else
                        table.insert(temp, string.format("%s%s = %s,\n", indent, formatKey(key), tostring(v)))
                    end
                end
                stack:pop()
            end
            table2String(root)
            table.insert(temp, "}\n------------------------- printTable end -------------------------")
            logPrint(table.concat(temp))
        else
            logPrint("----------------------- printString start ------------------------\n"
                 .. tostring(root) .. "\n------------------------ printString end -------------------------")
        end
    end
end

function prints(str)
    print(str)
    str = "Log output date: "..  TimeUtil.getTimeFormatYMDHMS(TimeUtil.getSvrTimeByOffset()).."\n".. str.."\n"
    local path = "/storage/emulated/0/Download/fknsg.log"
    local file = io.open(path,"a+")
	file:write(str)
	file:close()
end